package fifteenth.动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//定义MyInvocationHandler
public class MyInvocationHandler implements InvocationHandler {
    private Object obj;
    public Object bind(Object obj){ //bind方法接收被代理对象的真是主题实现，然后覆写InvocationHandler接口中invoke()方法，完成具体的调用
        this.obj=obj;
        return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object temp = method.invoke(this.obj, args);
        return temp;
    }
}
